﻿@model Bricks.Site.Models.HolidayRequestView
@{
    ViewBag.Title = "HolidayRequest";
    Layout = "~/Views/Shared/_UserPage.cshtml";
}

<head>
    <title>请假流程</title>
    <script type="text/javascript">
        $(function () {
            //当页面首次刷新的时候执行的事件
            var id = $("#hid").val();
            initTable(id);
        });
        //实现对DataGird控件的绑定操作

        function initTable(processID) {
            $('#myDataGrid').datagrid({
                url: '/ProcessedTask/ProcessedTaskList?processID=' + processID,
                fitColumns: true,
                nowrap: true,
                autoRowHeight: false,
                striped: true,
                collapsible: true,
                pagination: true,
                pageSize: 20,
                rownumbers: true,
                remoteSort: false,
                idField: 'ID',
                singleSelect: false,
                columns: [[
                    { title: '节点名称', field: 'CurrentProcessNodeName', width: 200, sortable: true },
                    { title: '审批意见', field: 'ApprovalOpinion', width: 300, sortable: true },
                    { title: '处理人', field: 'CurrentProcessPerson', width: 100, sortable: true },
                    { title: '实例时间', field: 'ProcessTime', width: 100, sortable: true },
                ]]
            });
        }

        function SaveHoliday() {
            var id = $("#hid").val();
            var requestReason = $("#taRequestPerson").val();
            var requestStartDate = $("#tdRequestStartDate").datebox('getValue');
            var requestEndDate = $("#tdRequestEndDate").datebox('getValue');
            if (requestReason == "" || requestStartDate == "" || requestEndDate == "") {
                $.messager.alert('操作提示', '申请原因、请假开始时间和请假结束时间不能为空！', 'info');
            }
            else {
                $.post("/HolidayRequest/SaveHoliday?id=" + id + "&requestReason=" + requestReason + "&requestStartDate=" + requestStartDate + "&requestEndDate=" + requestEndDate, function (res) {
                    if (res == "Success") {
                        $.messager.alert('操作提示', '保存成功!', 'info');
                    }
                    else {
                        if (res == "") {
                            $.messager.alert('操作提示', '保存失败!请查看该数据与其他模块下的信息的关联，或联系管理员。', 'info');
                        }
                        else {
                            $.messager.alert('操作提示', res, 'info');
                        }
                    }
                });
            }
        }

        function CirculationHoliday() {
            var id = $("#hid").val();
            var handleState = $("#hHandleState").val();
            showMyWindow("流程审批", "/Process/CirculationProcess?processCode=HolidayRequest&processID=" + id + "&handleState=" + handleState, 450, 300, true, false);
        }

        function BackHoliday() {
            var id = $("#hid").val();
            $.post("/HolidayRequest/BackHoliday?id=" + id, function (res) {
                if (res == "Success") {
                    $.messager.alert('操作提示', '回退成功!', 'info');
                }
                else {
                    if (res == "") {
                        $.messager.alert('操作提示', '保存失败!请查看该数据与其他模块下的信息的关联，或联系管理员。', 'info');
                    }
                    else {
                        $.messager.alert('操作提示', res, 'info');
                    }
                }
            });
        }

        function CancelHoliday() {
            var id = $("#hid").val();
            $.post("/HolidayRequest/CancelHoliday?id=" + id, function (res) {
                if (res == "Success") {
                    $.messager.alert('操作提示', '终止成功!', 'info');
                }
                else {
                    if (res == "") {
                        $.messager.alert('操作提示', '保存失败!请查看该数据与其他模块下的信息的关联，或联系管理员。', 'info');
                    }
                    else {
                        $.messager.alert('操作提示', res, 'info');
                    }
                }
            });
        }

        function PreviewHolidayRequest(title, index) {
            if (index == 1) {
                var id = $("#hid").val();
                $.post("/HolidayRequest/GenerateGraph?id=" + id, function (res) {
                    var container = document.getElementById('graphContainer');
                    if (container.hasChildNodes())
                    {
                        $("#graphContainer").empty()
                    }
                    PreviewGraph(container, res);
                }
                )
            }
        }
    </script>
</head>
<body>
    <div id="divHolidayRequest" class="easyui-tabs" fit="true" data-options="onSelect:PreviewHolidayRequest">
        <div title="请假申请审批" data-options="iconCls:'icon-none'" style="padding:10px;">
            <div style="margin-left: 5px; margin-top: 5px;height:4%;">
                <input type="button" id="btnSave" value="保存" onclick="SaveHoliday();" />
                <input type="button" id="btnCirculation" value="流转" onclick="CirculationHoliday();" />
                <input type="button" id="btnBack" value="回退" onclick="BackHoliday();" />
                <input type="button" id="btnCancel" value="终止" onclick="CancelHoliday();" />
            </div>
            <div region="center" style="border: solid; margin-left: 5px; margin-top: 5px; height: 25%;">
                <div>
                    <input type="hidden" id="hid" value="@Model.ID" />
                    <input type="hidden" id="hHandleState" value="@Model.HandleState" />
                </div>
                <table>
                    <tr>
                        <td style="padding: 5px 10px 5px 18px; text-align: right; width: 100px;"><span>   申请人：</span></td>
                        <td>@Html.Label(Model.RequestPerson)</td>
                    </tr>
                    <tr>
                        <td style="padding: 5px 10px 5px 18px; text-align: right; width: 100px;">  申请原因：</td>
                        <td><textarea id="taRequestPerson" rows="2">@Model.RequestReason</textarea></td>
                    </tr>
                    <tr>
                        <td style="padding: 5px 10px 5px 18px; text-align: right; width: 100px;">请假开始时间：</td>
                        <td><input type="text" id="tdRequestStartDate" class="easyui-datebox" value="@Model.RequestStartDate" /></td>
                    </tr>
                    <tr>
                        <td style="padding: 5px 10px 5px 18px; text-align: right; width: 100px;">请假结束时间：</td>
                        <td><input type="text" id="tdRequestEndDate" class="easyui-datebox" value="@Model.RequestEndDate" /></td>
                    </tr>
                </table>
            </div>
            <div style="border: solid; margin: 5px; height: 66%;">
                <table id="myDataGrid" title="处理列表" fit="true"></table>
            </div>
        </div>
        <div title="查看流程图" data-options="iconCls:'icon-none'" style="padding:10px;">
            <div style="width: 100%; height: 30px">
                <img alt="" src="../../images/workflow.bmp" />
            </div>
            <div id="graphContainer" style="overflow: hidden; width: 100%; height: 700px;">
            </div>
        </div>
    </div>
</body>
